<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TeacherGroupsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => 'required|unique:teacher_groups|max:255',
            'teach_value' => 'required|numeric',
        ];
        if ($this->isMethod('patch')){
            $id = $this->route('group');
            $rules['name'] = 'required|unique:teacher_groups,name,'.$id;
        }
        return $rules;
    }

    public function messages(){
        return [
            'name.required'        => '老师组名必填',
            'name.unique'          => '组名不唯一',
            'teach_value.required' => '课时费必填',
            'teach_value.numeric'  => '课时费必需是数字',
        ];
    }
}
